import { defineStore } from 'pinia';
import { messageFn } from '../../utils';
import { getRecordbills, getLaborchaarge, getRecordbillsNew } from '/@/api/comprehensive/paycos';
import { useLoading } from '/@/components/Loading';

interface paycosType {
  paycoslist: any;
  paymentlist: any[];
  recordidS: any[];
}

const [openFullLoading, closeFullLoading] = useLoading({
  tip: '加载中...',
});
export const paycosStore = defineStore('paycos_store', {
  state: (): paycosType => {
    return {
      paycoslist: {},
      //   存储缴费子项的数据
      paymentlist: [],
      // 存储选中的每一项roice_id
      recordidS: [],
    };
  },
  actions: {
    async setPaycosList(dataObj) {
      openFullLoading()
      try {
        const { code, data, msg } = await getRecordbillsNew(dataObj);
        if (code === 0) {
          this.paycoslist = data;
          return Promise.resolve();
        } else {
          messageFn('error', msg);
          return Promise.reject();
        }
      } finally {
        closeFullLoading()
      }
    },

    setpaymentlist(data) {
      this.paymentlist = data;
    },
    setrecordidS(data) {
      this.recordidS = data;
    },

    // 缴费
    async setLaborchaarge(dataObj: object) {
      openFullLoading()
      try {
        const { code, data, msg } = await getLaborchaarge(dataObj);
        if (code === 0) {
          // messageFn('success', msg);
          return true;
        } else {
          messageFn('error', msg);
          return false;
        }
      } finally {
        closeFullLoading()
      }
     
    },
  },
});
